package fourEightDays;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Day16 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String[] poke = in.nextLine().split("-");
            // 如果存在对王，直接返回对王
            if (poke[0].equals("joker JOKER") || poke[1].equals("joker JOKER")) {
                System.out.println("joker JOKER");
                return;
            }

            String[] poke1 = poke[0].split(" ");
            String[] poke2 = poke[1].split(" ");
            // 判断牌数是否相同（同类型比较）
            Map<String, Integer> map = new HashMap<String, Integer>() {
                {
                    put("3", 0);
                    put("4", 1);
                    put("5", 2);
                    put("6", 3);
                    put("7", 4);
                    put("8", 5);
                    put("9", 6);
                    put("10", 7);
                    put("J", 8);
                    put("Q", 9);
                    put("K", 10);
                    put("A", 11);
                    put("2", 12);
                    put("joker", 13);
                    put("JOKER", 14);


                }
            };
            if (poke1.length == poke2.length) {
                // 个子
                if (map.get(poke1[0]) - map.get(poke2[0]) > 0) {
                    System.out.println(poke[0]);
                } else {
                    System.out.println(poke[1]);
                }

            } else if (poke1.length != 4 && poke2.length != 4) {
                // 不存在对王，不能比较
                System.out.println("ERROR");

            } else if (poke1.length == 4 || poke2.length == 4) {
                // 不能存在対王，能比较
                String res = "";
                if (poke1.length == 4) {
                    res = poke[0];
                } else {
                    res = poke[1];
                }
                System.out.println(res);
            }
        }
    }
}
